package com.jizhi.springboot.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.jizhi.springboot.common.Configure;
import com.jizhi.springboot.common.RedisService;
import com.jizhi.springboot.service.UserService;
import com.jizhi.springboot.vo.UserVo;

//@RestController注解能够使项目支持Rest 相当于 @controller @responseBody
@RestController
@SpringBootApplication
//表示该controller类下所有的方法都公用的一级上下文根
@RequestMapping(value = "/springboot")
public class UserController {
	@Autowired
	private UserService userService;
	@Autowired
	private Configure configure;
	@Autowired
	private RedisService redisService;
	
    @RequestMapping(value = "/insertUser", method = RequestMethod.POST)
    String insertUser(UserVo user){
    	JSONObject json = new JSONObject();
    	try {
    		int id = userService.insert(user);
    		json.put("error_code", 0);
    		json.put("id", id);
    		json.put("name", configure.getName());
    		redisService.set("asdasd_aaaa", "测试数据", 100000);
    		System.out.println(redisService.get("asdasd_aaaa"));
		} catch (Exception e) {
			e.printStackTrace();
		}
        return json.toJSONString();
    }
}
